// pages/my/myset/myset.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:'',
    isPost:false,
    sex:["男","女"],
    sexs:'',
    sexIndex:0,
    name:'',
    password:'',
    phone:'',
    isSetInfo:false,
    checked:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(this.data.sex[0])
    this.setData({
      isSetInfo:getApp().globalData.isSetInfo,
      check:getApp().globalData.checked,
      isPost:getApp().globalData.isPost,
      name:getApp().globalData.username,
      
    })
    let that = this
    //填充头像
    if (app.globalData.userInfo){
      that.setData({
        userInfo: app.globalData.userInfo
      })
    }else{
      wx.getStorage({
        key: 'userInfo',
        success: function(res) {
          that.setData({
            userInfo: res.data
          })
        },
      })
    }
  },

  
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //接收用户输入的姓名
  inputName: function (e) {
    this.setData({
      name: e.detail.value,
    })
    console.log("姓名:"+this.data.name)
  },

  

  
  //密码
  inputPassword: function (e) {
    this.setData({
      password: e.detail.value,
    })
    console.log("密码:"+this.data.password)
  },
 
  //提交按钮，向数据库中存入数据
  tijiao: function () {
    var phone = "",
    phone =  this.data.phone;
    console.log(phone.length)
    if(this.data.password==null||this.data.name==null)
    {
      wx.showModal({
        title: '提示!',
        content: '请输入正确信息',
      })
    }else{
    var that = this;
    console.log("全局"+getApp().globalData.inspector_openid)
    wx.request({
      
      url:'http://47.94.215.148:8080/weiChe/bandOpenId',
      method:'POST',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data:{
        openId:getApp().globalData.inspector_openid,
        username:that.data.name,
        password:that.data.password,
      },
      success: function(res){
        if(res.data.status==1){
        console.log(res)
        getApp().globalData.isPost = true,
        getApp().globalData.username=that.data.name,
        console.log(getApp().globalData.isPost)
        wx.showModal({
          title: '提示',
          content: '绑定成功',
        })
        }
        else{
          wx.showModal({
            title: '提示',
            content: '绑定失败，请检查绑定信息',
          })
        }
      },
      fail: function(res){
        console.log(res)
        wx.showModal({
          title: '提示',
          content: '绑定失败，请检查绑定信息',
        })
      }
    })
    wx.navigateBack({   //成功后跳转回原页面
      url: '../my'
    })
  }
     
  }
})